$().ready(function(){
	
	//点击选择图片
    $("#Trading_one").click(function(){
        sessionStorage.setItem("orderTypeImg",0);
        location.href="Token_Trading_img.html";
    });
    $("#Trading_two").click(function(){
        sessionStorage.setItem("orderTypeImg",1);
        location.href="Token_Trading_img.html";
    });
    //选择快速或者精准 
    $('.Trading_header_BT').on("click",'span',function(e){
        e.stopPropagation();
        $(this).addClass('Trading_rapid').siblings('.Trading_rapid').removeClass('Trading_rapid');
        var i=$(this).index();
        i=0?sessionStorage.setItem("orderType",0):sessionStorage.setItem("orderType",1);       
    });
    $("#Trading_OK").click(function(){
    	if(!sessionStorage.getItem("orderType")){sessionStorage.setItem("orderType",0)};
    	sessionStorage.getItem("TradeImgName1")?sessionStorage.getItem("TradeImgName1"):sessionStorage.setItem("TradeImgName1","BTC");
    	sessionStorage.getItem("TradeImgName2")?sessionStorage.getItem("TradeImgName2"):sessionStorage.setItem("TradeImgName2","ETH");
    	location.href="Token_Trading_Transaction.html";
    })
    
	//交易的最新记录
    $.ajax({
    	url:"/sys/exchangeRate/thenearfuture",
    	success:function(r){
    		var list=r.doGet;
    		$.ajax({
    			url:"/sys/exchangeRate/coinlis",
    			success:function(r){
    				var imgName=r.doGet;
    				//return true;
    				 function formatDateTime(timeStamp) {
    			            var date = new Date();date.setTime(timeStamp * 1000);var y = date.getFullYear();var m = date.getMonth() + 1;m = m < 10 ? ('0' + m) : m;var d = date.getDate();d = d < 10 ? ('0' + d) : d;var h = date.getHours();h = h < 10 ? ('0' + h) : h;var minute = date.getMinutes();var second = date.getSeconds();minute = minute < 10 ? ('0' + minute) : minute;second = second < 10 ? ('0' + second) : second;
    			            return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    			        };
    			        var html="";
    			        var currImg={};
    			        for(var i=0;i<list.length;i++){
    			            var OrderName1=list[i].curOut;
    			            var OrderName2=list[i].curIn;
    			            var OrderTime= parseInt(list[i].timestamp); //时间戳
    			            
    			                for(var key in imgName ){
    			                    if(OrderName1==key){var nameMG1= imgName[key].image;}
    			                    if(OrderName2==key){
    			                    	if(imgName[key].image){
    			                    		 var nameMG2=imgName[key].image;
    			                    	} 
    			                    }
    			                }
    			                html+="<tr>"+
			                    "<td><img src="+nameMG1+"></td>"+
			                    "<td>"+"<img src='../../img/right-translate2.png' alt=''/>"+"</td>"+
			                    "<td><img src="+nameMG2+"></td>"+
			                    "<td >"+OrderName1 + ' 转换 '+OrderName2+"</td>"+
			                    "<td>"+ formatDateTime(OrderTime)+"</td>"+
			                    "</tr>";
    			        }
    			        $(".Trading_More .loading-box").css("display","none");
    			        $("#Trading_Order").empty();
			            $("#Trading_Order").html(html); 
    			        	        
    			}
    		})
    	}
    })
})